package logic

import (
	"context"
	"doc-manage/docrpc/docrpc"
	"doc-manage/docrpc/internal/svc"
	"doc-manage/model/mysql"
	"errors"

	"github.com/zeromicro/go-zero/core/logx"
)

type DocAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDocAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DocAddLogic {
	return &DocAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 添加
func (l *DocAddLogic) DocAdd(in *docrpc.DocAddRequest) (*docrpc.DocAddResponse, error) {
	// todo: add your logic here and delete this line

	doc := &mysql.Doctor{
		Username: in.Username,
		Tel:      in.Tel,
		Address:  in.Address,
	}

	err := doc.DocAdd(mysql.DB)
	if err != nil {
		return nil, errors.New("添加失败")
	}

	return &docrpc.DocAddResponse{
		DoctorId: int64(doc.ID),
	}, nil
}
